//
//  BEOptionalExtension.swift
//  BasicExtensions
//
//  Created by Fanxx on 2018/3/23.
//  Copyright © 2018年 fanxx. All rights reserved.
//

import Foundation

extension Optional: Comparable where Wrapped: Comparable {
    @inlinable public static func < (lhs: Self, rhs: Self) -> Bool {
        switch lhs {
        case .none:
            switch rhs {
            case .none: return false
            case .some(_): return true
            }
        case .some(let lv):
            switch rhs {
            case .none: return false
            case .some(let rv): return lv < rv
            }
        }
    }
}
extension Optional where Wrapped: Comparable {
    @inlinable public static func < (lhs: Self, rhs: Wrapped) -> Bool {
        return lhs < Optional(rhs)
    }
    @inlinable public static func < (lhs: Wrapped, rhs: Self) -> Bool {
        return Optional(lhs) < rhs
    }
    @inlinable public static func > (lhs: Self, rhs: Wrapped) -> Bool {
        return Optional(rhs) < lhs
    }
    @inlinable public static func > (lhs: Wrapped, rhs: Self) -> Bool {
        return rhs < Optional(lhs)
    }
    @inlinable public static func <= (lhs: Self, rhs: Wrapped) -> Bool {
        return !(lhs > rhs)
    }
    @inlinable public static func <= (lhs: Wrapped, rhs: Optional<Wrapped>) -> Bool {
        return !(lhs > rhs)
    }
    @inlinable public static func >= (lhs: Self, rhs: Wrapped) -> Bool {
        return !(lhs < rhs)
    }
    @inlinable public static func >= (lhs: Wrapped, rhs: Self) -> Bool {
        return !(lhs < rhs)
    }
}
